﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Lawyer.DAL
{
	/// <summary>
	/// 数据访问类:ArchiveInfo
	/// </summary>
	public partial class ArchiveInfo
	{
		public ArchiveInfo()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ArchiveID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from ArchiveInfo");
			strSql.Append(" where ArchiveID=@ArchiveID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ArchiveID", SqlDbType.VarChar,36)};
			parameters[0].Value = ArchiveID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Lawyer.Model.ArchiveInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ArchiveInfo(");
			strSql.Append("ArchiveID,Title,LawyerID,CustomID,IsAgency,AgencyID,AgencyRate,Status,EndDate,CreatedDate,CreatedBy,CheckedBy,CheckedDate,UpdatedDate,UpdatedBy)");
			strSql.Append(" values (");
			strSql.Append("@ArchiveID,@Title,@LawyerID,@CustomID,@IsAgency,@AgencyID,@AgencyRate,@Status,@EndDate,@CreatedDate,@CreatedBy,@CheckedBy,@CheckedDate,@UpdatedDate,@UpdatedBy)");
			SqlParameter[] parameters = {
					new SqlParameter("@ArchiveID", SqlDbType.VarChar,36),
					new SqlParameter("@Title", SqlDbType.VarChar,255),
					new SqlParameter("@LawyerID", SqlDbType.VarChar,36),
					new SqlParameter("@CustomID", SqlDbType.VarChar,36),
					new SqlParameter("@IsAgency", SqlDbType.Int,4),
					new SqlParameter("@AgencyID", SqlDbType.VarChar,36),
					new SqlParameter("@AgencyRate", SqlDbType.Float,8),
					new SqlParameter("@Status", SqlDbType.Int,4),
					new SqlParameter("@EndDate", SqlDbType.DateTime),
					new SqlParameter("@CreatedDate", SqlDbType.DateTime),
					new SqlParameter("@CreatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CheckedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CheckedDate", SqlDbType.DateTime),
					new SqlParameter("@UpdatedDate", SqlDbType.DateTime),
					new SqlParameter("@UpdatedBy", SqlDbType.VarChar,36)};
			parameters[0].Value = model.ArchiveID;
			parameters[1].Value = model.Title;
			parameters[2].Value = model.LawyerID;
			parameters[3].Value = model.CustomID;
			parameters[4].Value = model.IsAgency;
			parameters[5].Value = model.AgencyID;
			parameters[6].Value = model.AgencyRate;
			parameters[7].Value = model.Status;
			parameters[8].Value = model.EndDate;
			parameters[9].Value = model.CreatedDate;
			parameters[10].Value = model.CreatedBy;
			parameters[11].Value = model.CheckedBy;
			parameters[12].Value = model.CheckedDate;
			parameters[13].Value = model.UpdatedDate;
			parameters[14].Value = model.UpdatedBy;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Lawyer.Model.ArchiveInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ArchiveInfo set ");
			strSql.Append("Title=@Title,");
			strSql.Append("LawyerID=@LawyerID,");
			strSql.Append("CustomID=@CustomID,");
			strSql.Append("IsAgency=@IsAgency,");
			strSql.Append("AgencyID=@AgencyID,");
			strSql.Append("AgencyRate=@AgencyRate,");
			strSql.Append("Status=@Status,");
			strSql.Append("EndDate=@EndDate,");
			strSql.Append("CreatedDate=@CreatedDate,");
			strSql.Append("CreatedBy=@CreatedBy,");
			strSql.Append("CheckedBy=@CheckedBy,");
			strSql.Append("CheckedDate=@CheckedDate,");
			strSql.Append("UpdatedDate=@UpdatedDate,");
			strSql.Append("UpdatedBy=@UpdatedBy");
			strSql.Append(" where ArchiveID=@ArchiveID ");
			SqlParameter[] parameters = {
					new SqlParameter("@Title", SqlDbType.VarChar,255),
					new SqlParameter("@LawyerID", SqlDbType.VarChar,36),
					new SqlParameter("@CustomID", SqlDbType.VarChar,36),
					new SqlParameter("@IsAgency", SqlDbType.Int,4),
					new SqlParameter("@AgencyID", SqlDbType.VarChar,36),
					new SqlParameter("@AgencyRate", SqlDbType.Float,8),
					new SqlParameter("@Status", SqlDbType.Int,4),
					new SqlParameter("@EndDate", SqlDbType.DateTime),
					new SqlParameter("@CreatedDate", SqlDbType.DateTime),
					new SqlParameter("@CreatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CheckedBy", SqlDbType.VarChar,36),
					new SqlParameter("@CheckedDate", SqlDbType.DateTime),
					new SqlParameter("@UpdatedDate", SqlDbType.DateTime),
					new SqlParameter("@UpdatedBy", SqlDbType.VarChar,36),
					new SqlParameter("@ArchiveID", SqlDbType.VarChar,36)};
			parameters[0].Value = model.Title;
			parameters[1].Value = model.LawyerID;
			parameters[2].Value = model.CustomID;
			parameters[3].Value = model.IsAgency;
			parameters[4].Value = model.AgencyID;
			parameters[5].Value = model.AgencyRate;
			parameters[6].Value = model.Status;
			parameters[7].Value = model.EndDate;
			parameters[8].Value = model.CreatedDate;
			parameters[9].Value = model.CreatedBy;
			parameters[10].Value = model.CheckedBy;
			parameters[11].Value = model.CheckedDate;
			parameters[12].Value = model.UpdatedDate;
			parameters[13].Value = model.UpdatedBy;
			parameters[14].Value = model.ArchiveID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ArchiveID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ArchiveInfo ");
			strSql.Append(" where ArchiveID=@ArchiveID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ArchiveID", SqlDbType.VarChar,36)};
			parameters[0].Value = ArchiveID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string ArchiveIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ArchiveInfo ");
			strSql.Append(" where ArchiveID in ("+ArchiveIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Lawyer.Model.ArchiveInfo GetModel(string ArchiveID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ArchiveID,Title,LawyerID,CustomID,IsAgency,AgencyID,AgencyRate,Status,EndDate,CreatedDate,CreatedBy,CheckedBy,CheckedDate,UpdatedDate,UpdatedBy from ArchiveInfo ");
			strSql.Append(" where ArchiveID=@ArchiveID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ArchiveID", SqlDbType.VarChar,36)};
			parameters[0].Value = ArchiveID;

			Lawyer.Model.ArchiveInfo model=new Lawyer.Model.ArchiveInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ArchiveID"]!=null && ds.Tables[0].Rows[0]["ArchiveID"].ToString()!="")
				{
					model.ArchiveID=ds.Tables[0].Rows[0]["ArchiveID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Title"]!=null && ds.Tables[0].Rows[0]["Title"].ToString()!="")
				{
					model.Title=ds.Tables[0].Rows[0]["Title"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LawyerID"]!=null && ds.Tables[0].Rows[0]["LawyerID"].ToString()!="")
				{
					model.LawyerID=ds.Tables[0].Rows[0]["LawyerID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CustomID"]!=null && ds.Tables[0].Rows[0]["CustomID"].ToString()!="")
				{
					model.CustomID=ds.Tables[0].Rows[0]["CustomID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["IsAgency"]!=null && ds.Tables[0].Rows[0]["IsAgency"].ToString()!="")
				{
					model.IsAgency=int.Parse(ds.Tables[0].Rows[0]["IsAgency"].ToString());
				}
				if(ds.Tables[0].Rows[0]["AgencyID"]!=null && ds.Tables[0].Rows[0]["AgencyID"].ToString()!="")
				{
					model.AgencyID=ds.Tables[0].Rows[0]["AgencyID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AgencyRate"]!=null && ds.Tables[0].Rows[0]["AgencyRate"].ToString()!="")
				{
					model.AgencyRate=decimal.Parse(ds.Tables[0].Rows[0]["AgencyRate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Status"]!=null && ds.Tables[0].Rows[0]["Status"].ToString()!="")
				{
					model.Status=int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
				}
				if(ds.Tables[0].Rows[0]["EndDate"]!=null && ds.Tables[0].Rows[0]["EndDate"].ToString()!="")
				{
					model.EndDate=DateTime.Parse(ds.Tables[0].Rows[0]["EndDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CreatedDate"]!=null && ds.Tables[0].Rows[0]["CreatedDate"].ToString()!="")
				{
					model.CreatedDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreatedDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CreatedBy"]!=null && ds.Tables[0].Rows[0]["CreatedBy"].ToString()!="")
				{
					model.CreatedBy=ds.Tables[0].Rows[0]["CreatedBy"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CheckedBy"]!=null && ds.Tables[0].Rows[0]["CheckedBy"].ToString()!="")
				{
					model.CheckedBy=ds.Tables[0].Rows[0]["CheckedBy"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CheckedDate"]!=null && ds.Tables[0].Rows[0]["CheckedDate"].ToString()!="")
				{
					model.CheckedDate=DateTime.Parse(ds.Tables[0].Rows[0]["CheckedDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UpdatedDate"]!=null && ds.Tables[0].Rows[0]["UpdatedDate"].ToString()!="")
				{
					model.UpdatedDate=DateTime.Parse(ds.Tables[0].Rows[0]["UpdatedDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UpdatedBy"]!=null && ds.Tables[0].Rows[0]["UpdatedBy"].ToString()!="")
				{
					model.UpdatedBy=ds.Tables[0].Rows[0]["UpdatedBy"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ArchiveID,Title,LawyerID,CustomID,IsAgency,AgencyID,AgencyRate,Status,EndDate,CreatedDate,CreatedBy,CheckedBy,CheckedDate,UpdatedDate,UpdatedBy ");
			strSql.Append(" FROM ArchiveInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ArchiveID,Title,LawyerID,CustomID,IsAgency,AgencyID,AgencyRate,Status,EndDate,CreatedDate,CreatedBy,CheckedBy,CheckedDate,UpdatedDate,UpdatedBy ");
			strSql.Append(" FROM ArchiveInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "ArchiveInfo";
			parameters[1].Value = "ArchiveID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

